home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1993 September / September 93.iso / Archives / Utilities / System / FKey / FKeys / dcl-ANSI (all) / dcl-ANSI FKEY.c < prev    next >
Text File  |  1993-04-22  |  4KB  |  203 lines

  1. /*
  2.  * dcl-ANSI FKEY.c
  3.  *
  4.  * By Jamie McCarthy, April 92.  This is public domain.
  5.  *
  6.  * This source file provides a bridge between dcl-ANSI.c,
  7.  * which just does the translation, and the clipboard
  8.  * scrap and FKEY mechanism.
  9.  *
  10.  */
  11.  
  12.  
  13.  
  14. /******************************/
  15.  
  16. #include <SetupA4.h>
  17. #include <pascal.h>
  18. #include <ExternalInterface.h>
  19. #include <DialogUtilities.h>
  20.  
  21. #include "dcl-ANSI.h"
  22.  
  23. /******************************/
  24.  
  25. enum {
  26.     kNMiscCStrs = 28,
  27.     kNSpecifiers = 23
  28. } ;
  29.  
  30. char *gMiscCStr[kNMiscCStrs];
  31. char *gSpecifier[kNSpecifiers];
  32.  
  33. /******************************/
  34.  
  35. pascal void main(void);
  36.  
  37. void getCDeclaration(void);
  38. void putFinalString(void);
  39.  
  40. /******************************/
  41.  
  42.  
  43.  
  44. pascal void main(void)
  45. {
  46.     RememberA0();
  47.     SetUpA4();
  48.     
  49.     gError = noErr;
  50.     
  51.     getCDeclaration();
  52.     
  53.     startupDcl();
  54.     if (gError == noErr) {
  55.         declarator();
  56.     }
  57.     buildFinalString();
  58.     shutdownDcl();
  59.     
  60.     putFinalString();
  61.     
  62.     RestoreA4();
  63. }
  64.  
  65.  
  66.  
  67. /******************************/
  68.  
  69.  
  70.  
  71. void getCDeclaration(void)
  72. {
  73.     long theLength, theOffset;
  74.     gCDeclHndl = NewHandle(0);
  75.     
  76.     theLength = GetScrap(gCDeclHndl, 'TEXT', &theOffset);
  77.     if (theLength < 0) {
  78.         gError = theLength;
  79.         gCDeclHndl = NULL;
  80.     }
  81. }
  82.  
  83.  
  84.  
  85. void putFinalString(void)
  86. {
  87.     long theLength;
  88.     gError = ZeroScrap();
  89.     if (gError == noErr) {
  90.         theLength = strlen(gEnglish);
  91.         gError = PutScrap(theLength, 'TEXT', &gEnglish[0]);
  92.     }
  93.     
  94.         /*
  95.          * We need to tell whatever app we're in that it has a new clipboard,
  96.          * and that it needs to convert that clipboard to its own private
  97.          * format.  Here's how we do that.  Thanks to Bob Boonstra
  98.          * (jrb@mitre.org) for telling me how to do this.
  99.          */
  100.     
  101.     PostEvent(osEvt,
  102.         (suspendResumeMessage<<24) + resumeFlag + convertClipboardFlag);
  103. }
  104.  
  105.  
  106.  
  107. /******************************/
  108.  
  109.  
  110.  
  111. void startupCStrs(void)
  112. {
  113.         // If you add or remove strings, remember to change kNMiscCStrs.
  114.     gMiscCStr[0] = "missing left-parenthesis.";
  115.     gMiscCStr[1] = "missing right-parenthesis.";
  116.     gMiscCStr[2] = "expected an identifier or a dcl but didn’t find one.";
  117.     gMiscCStr[3] = "didn’t find a variable name.";
  118.     gMiscCStr[4] = "couldn’t find a type specifier (ANSI, unlike K&R 1st ed., requires one).";
  119.     gMiscCStr[5] = "syntax error.";
  120.     gMiscCStr[6] = "array syntax error.";
  121.     gMiscCStr[7] = "the English output string is too long. (!)";
  122.     gMiscCStr[8] = "function prototypes are nested too deep (my fault—sorry).";
  123.     gMiscCStr[9] = "a function cannot return an actual function—try a function pointer instead, maybe.";
  124.     gMiscCStr[10] = "a function cannot return an actual array—try a pointer instead, maybe.";
  125.     gMiscCStr[11] = "an array’s element type cannot be an actual function—try a pointer to function instead, maybe.";
  126.     gMiscCStr[12] = "A Mac OS error occurred. Your lucky number for today is ";
  127.     gMiscCStr[13] = ".";
  128.     gMiscCStr[14] = "The variable named “";
  129.     gMiscCStr[15] = "” is of type “";
  130.     gMiscCStr[16] = ".”";
  131.     gMiscCStr[17] = " ";
  132.     gMiscCStr[18] = "pointer to";
  133.     gMiscCStr[19] = "function";
  134.     gMiscCStr[20] = "with undefined parameters";
  135.     gMiscCStr[21] = "accepting a parameter list of type (";
  136.     gMiscCStr[22] = ", ";
  137.     gMiscCStr[23] = ") and";
  138.     gMiscCStr[24] = "returning type";
  139.     gMiscCStr[25] = "array";
  140.     gMiscCStr[26] = "of";
  141.     gMiscCStr[27] = "An error occurred: ";
  142.         // If you add or remove strings, remember to change kNSpecifiers.
  143.     gSpecifier[0] = "void";
  144.     gSpecifier[1] = "unsigned";
  145.     gSpecifier[2] = "signed";
  146.     gSpecifier[3] = "const";
  147.     gSpecifier[4] = "volatile";
  148.     gSpecifier[5] = "char";
  149.     gSpecifier[6] = "short";
  150.     gSpecifier[7] = "long";
  151.     gSpecifier[8] = "int";
  152.     gSpecifier[9] = "register";
  153.     gSpecifier[10] = "static";
  154.     gSpecifier[11] = "extern";
  155.     gSpecifier[12] = "auto";
  156.     gSpecifier[13] = "float";
  157.     gSpecifier[14] = "double";
  158.     gSpecifier[15] = "pascal";
  159.     gSpecifier[16] = "Handle";
  160.     gSpecifier[17] = "Ptr";
  161.     gSpecifier[18] = "Rect";
  162.     gSpecifier[19] = "Byte";
  163.     gSpecifier[20] = "Boolean";
  164.     gSpecifier[21] = "GrafPtr";
  165.     gSpecifier[22] = "WindowPtr";
  166. }
  167.  
  168.  
  169.  
  170. short getNMiscCStrs(void)
  171. {
  172.     return kNMiscCStrs;
  173. }
  174.  
  175.  
  176.  
  177. char *getMiscCStr(short index)
  178. {
  179.     return gMiscCStr[index-1];
  180. }
  181.  
  182.  
  183.  
  184. short getNSpecifiers(void)
  185. {
  186.     return kNSpecifiers;
  187. }
  188.  
  189.  
  190.  
  191. char *getSpecifier(short index)
  192. {
  193.     return gSpecifier[index-1];
  194. }
  195.  
  196.  
  197.  
  198. void shutdownCStrs(void)
  199. {
  200.     
  201. }
  202.  
  203.